package com.kanche.bigbaby.collection.dialog;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Chenshao_Young on 15/4/28.
 */
public class ListChoiceMenuDialog extends KancheDialogFragment{

    List<String> data = new ArrayList<>();
    OnMenuClick click ;

    public OnMenuClick getClick() {
        return click;
    }

    public void setClick(OnMenuClick click) {
        this.click = click;
    }

    public List<String> getData() {
        return data;
    }

    public void setData(List<String> data) {
        this.data = data;
    }

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {

        String[] strs = new String[data.size()];
        strs = data.toArray(strs);

        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setTitle("请选择")
                .setItems(strs,
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                                click.onMenuClick(which,data.get(which));

                            }
                        }
                )
                .setCancelable(false);

        return builder.create();
    }

    public interface OnMenuClick{
        void onMenuClick(int which, String s);
    }
}
